package com.dingding.manager.modules.order.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dingding.manager.common.dao.Page;
import com.dingding.manager.core.shiro.ShiroKit;
import com.dingding.manager.modules.dirver.dto.RespResult;
import com.dingding.manager.modules.order.dto.ReqOrderDTO;
import com.dingding.manager.modules.order.dto.ResOrderDetailsDTO;
import com.dingding.manager.modules.order.dto.ResOrderListDTO;
import com.dingding.manager.modules.order.service.IOrderService;

/**
 * 
 * @ClassName: OrderController 
 * @Description: 订单相关的controller
 * @author hufan
 * @date 2016年12月7日 下午4:32:55 
 *
 */
@Controller
@RequestMapping("/order")
public class OrderController {

	@Resource(name = "orderService")
	private IOrderService orderService;
	
	/**
	 * 
	 * @Title: listOrders 
	 * @Description: 查询订单列表
	 * @param reqOrderDTO
	 * @param response
	 * @param @return  参数说明 
	 * @return RespResult<ResOrderDTO>    返回类型 
	 * @throws
	 */
	@ResponseBody
	@RequestMapping(value = "/list", method = { RequestMethod.GET })
	public RespResult<ResOrderListDTO> listOrders(ReqOrderDTO reqOrderDTO,HttpServletResponse response) {

		Page<ResOrderListDTO> res = orderService.getOrderDTOListByPage(reqOrderDTO);
		
		// datatable固定相应格式
		RespResult<ResOrderListDTO> results = new RespResult<ResOrderListDTO>();

		results.setAaData(res.getList());
		results.setiTotalRecords(res.getTotalPage());
		results.setiTotalDisplayRecords(res.getTotalRow());

		return results;

	}
	
	/**
	 * 
	 * @Title: listOrders 
	 * @Description: 订单详情
	 * @param  参数说明 
	 * @author hufan
	 * @return 返回类型 
	 * @throws
	 */
	@ResponseBody
	@RequestMapping(value = "/details", method = { RequestMethod.GET })
	public ResOrderDetailsDTO orderDetails(@RequestParam(value = "oid") String oid,HttpServletResponse response) {

		ResOrderDetailsDTO results = orderService.getOrderDetailsDTOByOrderId(oid);
		return results;

	}
	
	/**
	 * 
	 * @Title: isManager 
	 * @Description: 判断是否为admin用户
	 * @param  参数说明 
	 * @author hufan
	 * @return 返回类型 
	 * @throws
	 */
	@ResponseBody
	@RequestMapping(value = "/isManager", method = { RequestMethod.GET })
	public boolean isManager() {
		//获取当前用户判断当前用户是否为admin用户
		return ShiroKit.isManager();
	}
}
